﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DeviceInfoManage.BusinessLogicLayer;

public partial class BurstRegister : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["type"]))
        {
            hidType.Value = Request.QueryString["type"];
        }
        else
        {
            Response.Write("<script>alert('参数错误!');</script>");
        }
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            hidId.Value = Request.QueryString["id"];
        }
        if (hidType.Value == "2")
        {
            BindData();
        }

    }

    private void BindData()
    {
        BurstEvent be = (new BurstEvent()).GetModel(int.Parse(hidId.Value));
        ddlMaintPerson.Text = be.UserName;
        startTime.Value = be.Date.ToString();
        txtErrorReason.Text = be.Reason;
    }

    /*添加设备信息*/
    protected void Btn_Add_Click(object sender, EventArgs e)
    {

        BurstEvent be = new BurstEvent();
        be.UserName = ddlMaintPerson.SelectedItem.Text;
        be.Date = Convert.ToDateTime(startTime.Value);
        be.Reason = txtErrorReason.Text;
        if (hidId.Value == "")
        {
            if (be.Add(be) != -1)
                Response.Write("<script>alert('添加成功!');</script>");//location.href='MaintRecordRegister.aspx';
            else
                Response.Write("<script>alert('添加失败!');</script>");
        }
        else
        {
            be.ID = int.Parse(hidId.Value);
            be.Update(be);
            Response.Write("<script>alert('更新成功!');</script>");
        }
    }
}
